package com.adou.service.impl.base;

import com.adou.common.mapper.base.BaseDao;
import com.adou.service.base.BaseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class BaseServiceImp<T> implements BaseService<T> {

    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    protected BaseDao<T> baseDao;

    @Override
    public int insert(T o) {
        return baseDao.insert(o);
    }

    @Override
    public int delete(T o) {
        return baseDao.delete(o);
    }

    @Override
    public int deleteBatch(List<T> o) {
        return baseDao.deleteBatch(o);
    }

    @Override
    public int update(T o) {
        return baseDao.update(o);
    }

    @Override
    public List<T> find(T o) {
        return baseDao.find(o);
    }

    @Override
    public Map<String, Object> findByPage(int pageNum, int pageSize, T o) {
        Page<?> page = PageHelper.startPage(pageNum, pageSize);
        List<T> tList=baseDao.findByPage(o);
        Map<String, Object> data = new HashMap<>();
        data.put("totalpage", page.getPages());
        data.put("totalcount", page.getTotal());
        data.put("pageNum", pageNum);
        data.put("pageSize", pageSize);
        data.put("list", tList);
        return data;
    }

    @Override
    public int count(T o) {
        return baseDao.count(o);
    }
}
